package cn.sdormitory.sys.service.impl;

import cn.sdormitory.sys.dao.SysAppVersionDao;
import cn.sdormitory.sys.entity.SysAppVersion;
import cn.sdormitory.sys.service.SysAppVersionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class SysAppVersionServiceImpl extends ServiceImpl<SysAppVersionDao, SysAppVersion> implements SysAppVersionService {

    @Autowired
    SysAppVersionDao appVersionDao;

    @Override
    public IPage<SysAppVersion> findAppVersionByPageList(SysAppVersion appVersion) {
        QueryWrapper<SysAppVersion> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(appVersion.getVersionName())){
            wrapper.eq("version_name",appVersion.getVersionName());
        }
        return page(new Page<>(appVersion.getPageNum(),appVersion.getPageSize()),wrapper.orderByDesc("create_time"));
    }

    @Override
    public Integer createAppVersion(SysAppVersion appVersion) {
        appVersion.setCreateTime(new Date());
        return appVersionDao.insert(appVersion);
    }

    @Override
    public Integer deleteAppVersion(Long id) {
        return appVersionDao.deleteById(id);
    }
}
